package com.cyw.search.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.elasticsearch.common.geo.GeoPoint;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Chenyw
 * @Date: 2022/11/06/19:29
 */
public class GetAddressByGeoPointUtil {

   public static String getAddress(GeoPoint geoPoint){
        String url = "https://restapi.amap.com/v3/geocode/regeo";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("key","7a2411eba6be444a979db71664f818a6");
        paramMap.put("location",geoPoint.getLon()+","+geoPoint.getLat());
        paramMap.put("radius",1000);
        paramMap.put("extensions","all");
        JSONObject jsonObject = JSON.parseObject(HttpUtil.get(url, paramMap));
        return jsonObject.getJSONObject("regeocode").getString("formatted_address");
    }

  public static void main(String[] args) {

  }
}
